//
// Description: 1870. 准时到达的列车最小时速
// Created by Loading on 2021/8/14.
//

#include <bits/stdc++.h>

using namespace std;

int minSpeedOnTime(vector<int> &dist, double hour) {
    // 最后一趟列车发车时间大于等于 hour，不可能到达
    if ((int) dist.size() - 1 >= hour) {
        return -1;
    }
    // double 类型精度
    const static double ESP = 1e-8;

    // 判断当前速度能否到达
    auto check = [&](int speed) {
        double time_cnt = 0;
        for (int i = 0; i < dist.size() - 1; ++i) {
            time_cnt += ceil((double) dist[i] / speed - ESP);
        }
        // 注意最后一趟列车下车后无需再等待整数时间，因为后面没有列车了
        time_cnt += (double) dist.back() / speed;

        return time_cnt <= hour;
    };

    // 速度的最小值和最大值
    int l = 1, r = 1e7;
    // 二分查找最小速度
    while (l < r) {
        int mid = l + (r - l) / 2;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    return l;
}

int main() {
    vector<int> dist = {1, 3, 2};
    double hour = 1.9;
    int min_speed = minSpeedOnTime(dist, hour);
    cout << min_speed << endl;
}